<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>8.事件冒泡</title>
    <style>
        .d1 {
            width: 300px;
            height: 300px;
            background-color: aquamarine;
        }

        .s1 {
            width: 150px;
            height: 150px;
            background-color: red;
        }
    </style>
</head>

<body>
    <div class="d1">
        父元素
        <div class="s1">
            子元素
        </div>
    </div>
</body>
<script>
    var d1 = document.getElementsByClassName('d1')[0]
    var s1 = document.getElementsByClassName('s1')[0]
    //第三个参数为true时候，在捕获阶段就会执行
    d1.addEventListener('click', function (e) {
        console.log('父元素点击了')
    }, false)
    s1.addEventListener('click', function (e) {
        console.log('子元素点击了')
    }, false)
    document.addEventListener('click', function (e) {
        console.log('文档对象点击了')
    }, false)
    d1.onclick = function (e) {
        console.log('onclick父元素点击了')
    }
    s1.onclick = function (e) {
        console.log('onclick子元素元素点击了')
    }
</script>

</html>